package cn.wp.ewallet.wallet.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.wp.common.core.model.WpPage;
import cn.wp.common.core.util.BeanUtil;
import cn.wp.ewallet.common.model.dto.MoneyTypeInfoDto;
import cn.wp.ewallet.common.service.MoneyTypeInfoService;
import cn.wp.ewallet.wallet.dao.RechargeShqcLogDao;
import cn.wp.ewallet.wallet.extension.constant.EwalletWalletConstant;
import cn.wp.ewallet.wallet.extension.util.EwalletWalletUtil;
import cn.wp.ewallet.wallet.model.dto.MentionMoneyInfoDto;
import cn.wp.ewallet.wallet.model.dto.RechargeLogDto;
import cn.wp.ewallet.wallet.model.dto.RechargeShqcLogDto;
import cn.wp.ewallet.wallet.model.entity.MentionMoneyInfoDoo;
import cn.wp.ewallet.wallet.model.entity.RechargeLogDoo;
import cn.wp.ewallet.wallet.model.entity.RechargeShqcLogDo;
import cn.wp.ewallet.wallet.service.RechargeShqcLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Beans;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @ClassName RechargeShqcLogServiceImpl
 * @Author ruixule
 * @Date 2020/1/16 21:03
 */
@Service
public class RechargeShqcLogServiceImpl implements RechargeShqcLogService {

    @Autowired
    private RechargeShqcLogDao rechargeShqcLogDao;

    @Autowired
    private MoneyTypeInfoService moneyTypeInfoService;

    /**
     * 获取充值记录
     * @param rechargeLogDto
     * @param wpPage
     * @return
     */
    @Override
    public WpPage<RechargeShqcLogDto> getAllRechargeLog(RechargeLogDto rechargeLogDto, WpPage wpPage) {

        WpPage<RechargeShqcLogDo> rechargeShqcLogDoWpPage = rechargeShqcLogDao.selectAllRechargeLog(BeanUtil.copyProperties(rechargeLogDto, RechargeLogDoo.class), wpPage);
        MoneyTypeInfoDto moneyTypeInfoDto = moneyTypeInfoService.getMoneyTypeInfoByMoneyTypeId(EwalletWalletConstant.MONEY_TYPE_SHQC);
        return rechargeShqcLogDoWpPage.doConvertDto(RechargeShqcLogDto.class, new BeanUtil.Processor<RechargeShqcLogDo, RechargeShqcLogDto>() {
            @Override
            public void convert(RechargeShqcLogDo source, RechargeShqcLogDto target) {
                if (null != source.getShqcAmount()) {
                    target.setShqcAmount(EwalletWalletUtil.toUpperWei(source.getShqcAmount(), new BigDecimal(moneyTypeInfoDto.getMoneyTypeUnit())));
                }
                target.setOperTime(DateUtil.formatDateTime(source.getOperTime()));
            }
        });
    }
}
